/*
 * NewJPanel.java
 *
 * Created on July 28, 2008, 8:10 PM
 */

package schedule_master;
import javax.swing.JFrame;
import java.sql.*;
import java.util.ArrayList;
import javax.swing.JComboBox;
import java.awt.Cursor;
import java.awt.Color;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

/**
 *
 * @author  PGSIST
 */

public class Filter extends javax.swing.JPanel {
    Schedule_MasterView smv;
    int numteachers=5;
    TableModel tablemodel   = new AbstractTableModel() {
            public int getColumnCount() { return 9; }
             public int getRowCount() { return smv.selectedTeachers.size();}
              public Object getValueAt(int row, int col) { 
              return((smv.selectedTeachers.size()>0&&row<smv.selectedTeachers.size())?(((col==0)?(smv.selectedTeachers.get(row).name)
                  :(smv.selectedTeachers.get(row).periods[col-1]))
              ):("No Teachers"))
                      ; 
          }
      };
    /** Creates new form NewJPanel */
    public Filter(Schedule_MasterView smv1) {
        smv=smv1;
        
        initComponents();
        jPanel1.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
        getFilters();
       
      
      

        ScheduleTable.setSelectionBackground(Color.red);
        ScheduleTable.setBackground(Color.white);
        ScheduleTable.setGridColor(Color.orange);
        ScheduleTable.setFont(new java.awt.Font("Times New Roman", java.awt.Font.PLAIN,15));
        ScheduleTable.setRowHeight(20);
 
        
    }
    public void getFilters(){
        int[] filts=new int[4];
        filts=smv.filters;
        DepartmentComboBox.setSelectedIndex(filts[0]);
        TeacherComboBox.setSelectedIndex(filts[1]);
        ClassComboBox.setSelectedIndex(filts[2]);
        PeriodComboBox.setSelectedIndex(filts[3]);
        return;
    }
     public JComboBox getDepartmentComboBox(){
       ArrayList<String> departments = new ArrayList<String>();
       departments.add("Department");
       // departments.add("Department");
        // Try to access the database, otherwise, catch the exception
        try{
            String driver = "com.mysql.jdbc.Driver";
            Class.forName(driver);
        
            String url = "jdbc:mysql://pgsist.org:3306/2008_itp0";
            String userNameSQL = "itp0";
            String passwordSQL = "frebre3w";
            String deptIDQuery = "Select deptID " +
                                 "FROM tblDepartments " +
                                 "WHERE true";
            String deptNameQuery = "Select deptName " +
                               "FROM tblDepartments " +
                               "WHERE 1";
            
            
            System.out.println("Connecting to database...");
            Connection conn = DriverManager.getConnection(url, userNameSQL, passwordSQL);
            System.out.println("Done.");
        
            Statement st = conn.createStatement();
            
            ResultSet res = st.executeQuery(deptIDQuery);
            
            // Count the number of departments
            int i = 1;
            
            // While there is an item in deptID column of tblDepartments
            while(res.next()){
                // Add the current deptID to department array of current index
                departments.add( res.getString(1));
                // Increment the index of the array
                i++;
            } 
            
            // Set i back to zero
            i = 1;
            res = st.executeQuery(deptNameQuery);
            
            // While there is an item in deptName column of tblDepartments
            while(res.next()){
                // Concatenate the current deptName to department array of current index
                
                departments.set(i, departments.get(i) + " " + res.getString(1));
                
                // Increment the index of the array
                i++;
            }
            
            
            return new JComboBox(departments.toArray());
        } catch (Exception e){
            System.err.println(e);
        }
        return null;
    }
public JComboBox getTeacherComboBox(String dept, JComboBox combo){
       ArrayList<String> teachers = new ArrayList<String>();
       
        teachers.add("Teacher");
        // Try to access the database, otherwise, catch the exception
        try{
            String driver = "com.mysql.jdbc.Driver";
            Class.forName(driver);
        
            String url = "jdbc:mysql://pgsist.org:3306/2008_itp0";
            String userNameSQL = "itp0";
            String passwordSQL = "frebre3w";
            String teacherIDQuery = "Select teacherID " +
                                 "FROM tblTeachers " +
                                 "WHERE deptID=" + dept;
            String teacherNameQuery = "Select lastName " +
                               "FROM tblTeachers " +
                               "WHERE deptID=" + dept;
            
            
            System.out.println("Connecting to database...");
            Connection conn = DriverManager.getConnection(url, userNameSQL, passwordSQL);
            System.out.println("Done.");
        
            Statement st = conn.createStatement();
            
            ResultSet res = st.executeQuery(teacherIDQuery);
            
            // Count the number of departments
            int i = 0;
            
            // While there is an item in deptID column of tblDepartments
            while(res.next()){
                // Add the current deptID to department array of current index
                teachers.add( res.getString(1));
                // Increment the index of the array
                i++;
            } 
            
            // Set i back to zero
            i = 1;
            res = st.executeQuery(teacherNameQuery);
            
            // While there is an item in deptName column of tblDepartments
            while(res.next()){
                // Concatenate the current deptName to department array of current index
                
                teachers.set(i, teachers.get(i) + " " + res.getString(1));
                
                // Increment the index of the array
                i++;
            }
            
            combo.removeAllItems();
            
            for (int a=0;a<teachers.size();a++)
                combo.addItem(teachers.get(a));
            //return new JComboBox(teachers.toArray());
            return combo;
        } catch (Exception e){
            System.err.println(e);
        }
        return null;
    }
public JComboBox getClassComboBox(String dept, JComboBox combo){
       ArrayList<String> classes = new ArrayList<String>();
       
        classes.add("Class");
        // Try to access the database, otherwise, catch the exception
        try{
            String driver = "com.mysql.jdbc.Driver";
            Class.forName(driver);
        
            String url = "jdbc:mysql://pgsist.org:3306/2008_itp0";
            String userNameSQL = "itp0";
            String passwordSQL = "frebre3w";
            String teacherIDQuery = "Select courseID " +
                                 "FROM tblCourses " +
                                 "WHERE deptID=" + dept;
            String teacherNameQuery = "Select courseName " +
                               "FROM tblCourses " +
                               "WHERE deptID=" + dept;
            
            
            System.out.println("Connecting to database...");
            Connection conn = DriverManager.getConnection(url, userNameSQL, passwordSQL);
            System.out.println("Done.");
        
            Statement st = conn.createStatement();
            
            ResultSet res = st.executeQuery(teacherIDQuery);
            
            // Count the number of departments
            int i = 0;
            
            // While there is an item in deptID column of tblDepartments
            while(res.next()){
                // Add the current deptID to department array of current index
                classes.add( res.getString(1));
                // Increment the index of the array
                i++;
            } 
            
            // Set i back to zero
            i = 1;
            res = st.executeQuery(teacherNameQuery);
            
            // While there is an item in deptName column of tblDepartments
            while(res.next()){
                // Concatenate the current deptName to department array of current index
                
                classes.set(i, classes.get(i) + " " + res.getString(1));
                
                // Increment the index of the array
                i++;
            }
            combo.removeAllItems();
            for (int a=0;a<classes.size();a++){
                combo.addItem(classes.get(a));
               
            }
            //return new JComboBox(teachers.toArray());
            return combo;
        } catch (Exception e){
            System.err.println(e);
        }
        return null;
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        TeacherComboBox =
        getTeacherComboBox(
            //(DepartmentComboBox.getSelectedItem().toString().charAt(1)==' ')?DepartmentComboBox.getSelectedItem().toString().substring(0,1):DepartmentComboBox.getSelectedItem().toString().substring(0,2)
            ""+smv.currentDeptID
            , new JComboBox());
        ClassComboBox = getClassComboBox(""+smv.currentDeptID,new JComboBox());
        PeriodComboBox = new javax.swing.JComboBox();
        FilterButton = new javax.swing.JButton();
        ResetButton = new javax.swing.JButton();
        EditScheduleButton = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        HomeButton = new javax.swing.JButton();
        LogoutButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        ScheduleTable = new JTable(tablemodel);
        jSeparator1 = new javax.swing.JSeparator();
        DepartmentComboBox = getDepartmentComboBox();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(schedule_master.Schedule_MasterApp.class).getContext().getResourceMap(Filter.class);
        jPanel1.setBackground(resourceMap.getColor("jPanel1.background")); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        TeacherComboBox.setName("TeacherComboBox"); // NOI18N

        ClassComboBox.setName("ClassComboBox"); // NOI18N

        PeriodComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Period", "Period 1", "Period 2", "Period 3", "Period 4", "Period 5", "Period 6", "Period 7", "Period 8" }));
        PeriodComboBox.setName("PeriodComboBox"); // NOI18N

        FilterButton.setText(resourceMap.getString("FilterButton.text")); // NOI18N
        FilterButton.setName("FilterButton"); // NOI18N
        FilterButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FilterButtonActionPerformed(evt);
            }
        });

        ResetButton.setText(resourceMap.getString("ResetButton.text")); // NOI18N
        ResetButton.setName("ResetButton"); // NOI18N
        ResetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ResetButtonActionPerformed(evt);
            }
        });

        EditScheduleButton.setText(resourceMap.getString("EditScheduleButton.text")); // NOI18N
        EditScheduleButton.setName("EditScheduleButton"); // NOI18N
        EditScheduleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditScheduleButtonActionPerformed(evt);
            }
        });

        jPanel5.setBackground(resourceMap.getColor("jPanel5.background")); // NOI18N
        jPanel5.setMaximumSize(new java.awt.Dimension(955, 600));
        jPanel5.setName("jPanel5"); // NOI18N

        jLabel7.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel2.setIcon(resourceMap.getIcon("jLabel2.icon")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        HomeButton.setText(resourceMap.getString("HomeButton.text")); // NOI18N
        HomeButton.setName("HomeButton"); // NOI18N
        HomeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HomeButtonActionPerformed(evt);
            }
        });

        LogoutButton.setText(resourceMap.getString("LogoutButton.text")); // NOI18N
        LogoutButton.setName("LogoutButton"); // NOI18N
        LogoutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LogoutButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 551, Short.MAX_VALUE)
                        .addComponent(HomeButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(LogoutButton)
                        .addGap(320, 320, 320))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addContainerGap(1355, Short.MAX_VALUE))))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(LogoutButton)
                        .addComponent(HomeButton))
                    .addComponent(jLabel2)
                    .addComponent(jLabel7))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        ScheduleTable.setName("ScheduleTable"); // NOI18N
        jScrollPane1.setViewportView(ScheduleTable);
        ScheduleTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("ScheduleTable.columnModel.title0")); // NOI18N
        ScheduleTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("ScheduleTable.columnModel.title1")); // NOI18N
        ScheduleTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("ScheduleTable.columnModel.title2")); // NOI18N
        ScheduleTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("ScheduleTable.columnModel.title3")); // NOI18N
        ScheduleTable.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("ScheduleTable.columnModel.title4")); // NOI18N
        ScheduleTable.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("ScheduleTable.columnModel.title5")); // NOI18N
        ScheduleTable.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("ScheduleTable.columnModel.title6")); // NOI18N
        ScheduleTable.getColumnModel().getColumn(7).setHeaderValue(resourceMap.getString("ScheduleTable.columnModel.title7")); // NOI18N
        ScheduleTable.getColumnModel().getColumn(8).setHeaderValue(resourceMap.getString("ScheduleTable.columnModel.title8")); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        DepartmentComboBox.setName("DepartmentComboBox"); // NOI18N
        DepartmentComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DepartmentComboBoxActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(DepartmentComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TeacherComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ClassComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PeriodComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(FilterButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ResetButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(EditScheduleButton)
                .addGap(355, 355, 355))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(20, Short.MAX_VALUE)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 1335, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 906, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(415, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TeacherComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ClassComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(PeriodComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(FilterButton)
                    .addComponent(ResetButton)
                    .addComponent(EditScheduleButton)
                    .addComponent(jLabel1)
                    .addComponent(DepartmentComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(209, 209, 209))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 905, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void HomeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HomeButtonActionPerformed
JFrame frame= new JFrame("Welcome");
  frame.add( new HomePage(smv));
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setVisible(true);
frame.pack();// TODO add your handling code here:
kill();
}//GEN-LAST:event_HomeButtonActionPerformed

private void LogoutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LogoutButtonActionPerformed
smv.getFrame().setVisible(true);
    //Schedule_MasterApp.getApplication().show(new Schedule_MasterView(Schedule_MasterApp.getApplication()));
    kill();// TODO add your handling code here:
}//GEN-LAST:event_LogoutButtonActionPerformed

private void EditScheduleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditScheduleButtonActionPerformed
JFrame frame= new JFrame("Let's edit some schedules... to death!");
  frame.add( new Edit_Schedule(smv));
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setVisible(true);
frame.pack();
kill();
}//GEN-LAST:event_EditScheduleButtonActionPerformed

private void FilterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FilterButtonActionPerformed
smv.selectedTeachers.get((TeacherComboBox.getSelectedIndex()-1>=0)?(TeacherComboBox.getSelectedIndex()-1):(0)).periods[(PeriodComboBox.getSelectedIndex()-1>=0)?PeriodComboBox.getSelectedIndex()-1:0]=ClassComboBox.getSelectedItem().toString();
//smv.selectedTeachers.get(2).periods[3]="BOOOOOOOOOOOOOOOO";
    JFrame frame= new JFrame("Filterification Time some more");
smv.setFilters(new int[]{DepartmentComboBox.getSelectedIndex(),
        TeacherComboBox.getSelectedIndex(),
        ClassComboBox.getSelectedIndex(),
        PeriodComboBox.getSelectedIndex()}
        );
  frame.add( new Filter(smv));
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setVisible(true);
frame.pack();

frame.setVisible(true);
kill();


// TODO add your handling code here:
}//GEN-LAST:event_FilterButtonActionPerformed

private void ResetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ResetButtonActionPerformed
// TODO add your handling code here:
    DepartmentComboBox.setSelectedIndex(0);
        TeacherComboBox.setSelectedIndex(0);
        ClassComboBox.setSelectedIndex(0);
        PeriodComboBox.setSelectedIndex(0);
    return;
}//GEN-LAST:event_ResetButtonActionPerformed

private void DepartmentComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DepartmentComboBoxActionPerformed
// TODO add your handling code here:
    System.out.println("Action");
     if (!DepartmentComboBox.getSelectedItem().toString().equals("Department")){
        System.out.println("didn't.");
        String s="";
        try{
    s+=  (Integer.parseInt(DepartmentComboBox.getSelectedItem().toString().substring(0, 2)));
    }
    catch(java.lang.NumberFormatException nfe){
        s+=  (Integer.parseInt(DepartmentComboBox.getSelectedItem().toString().substring(0, 1)));
    
    }
        smv.currentDeptID=Integer.parseInt(s);
        smv.setSelectedTeachers();
        TeacherComboBox=getTeacherComboBox(s, TeacherComboBox);
        ClassComboBox=getClassComboBox(s, ClassComboBox);
    }
    else 
        System.out.println("Entered in departments.");
    try{
      TeacherComboBox.setEnabled(DepartmentComboBox.getSelectedItem()!="Department");}
    catch(java.lang.NullPointerException npe){
        
        System.out.println("TeacherComboBox PROBLEM");
    }
     PeriodComboBox.setEnabled(DepartmentComboBox.getSelectedItem()!="Department");
     ClassComboBox.setEnabled(DepartmentComboBox.getSelectedItem()!="Department");
     FilterButton.setEnabled(DepartmentComboBox.getSelectedItem()!="Department");
     
}//GEN-LAST:event_DepartmentComboBoxActionPerformed
private void kill(){
    
     ( (JFrame)(this.getTopLevelAncestor())).dispose();
    
}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox ClassComboBox;
    private javax.swing.JComboBox DepartmentComboBox;
    private javax.swing.JButton EditScheduleButton;
    private javax.swing.JButton FilterButton;
    private javax.swing.JButton HomeButton;
    private javax.swing.JButton LogoutButton;
    private javax.swing.JComboBox PeriodComboBox;
    private javax.swing.JButton ResetButton;
    private javax.swing.JTable ScheduleTable;
    private javax.swing.JComboBox TeacherComboBox;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables

}
